<template lang="html">
  <div class="user_page">
    <div class="user_page_prd_top"></div>
    <div class="user_page_prd_content">
      <div class="user_page_prd_list">
        <template v-for="(item, index) in prd_list">
          <div :class="item.is_boom === 1 ? 'limit_product_content product_content' : 'product_content'" :key="index">
            <div class="vip_product_card_left" :style="{backgroundImage: 'url('+item.product_image+')'}"></div>
            <div class="vip_product_card">
              <div class="vip_product_card_middle">
                <div class="vip_product_card_middle_top">
                  <p><span>￥</span>{{item.coupon_total}}</p>
                  <p>{{item.coupon_type}}</p>
                  <p>多重权益超值享受</p>
                </div>
                <div class="vip_product_card_middle_bottom">
                  <img src="../../assets/image/member/vip_prd_right.png" alt="">
                </div>
              </div>
              <div class="vip_product_card_right">
                <div class="vip_product_card_right_top">
                  <p>获超值商品 + {{item.rights_title}}</p>
                </div>
                <div class="vip_product_card_right_bottom">
                  <p><span>￥</span>{{item.product_unit_price}}</p>
                </div>
              </div>
            </div>
            <div class="vip_product_details">
              <div class="vip_product_details_left">
                <h3>{{item.product_short_name}}</h3>
                <p>{{item.product_tips}}</p>
              </div>
              <div class="vip_product_details_right" @click="continueBuy(item)">
                <div :class="isVip ? 'vip_prd_invite_btn' : 'vip_product_btn'">立即参加</div>
                <!-- <img :src="isVip ? getImgInviteUrl() : getImgBuyUrl()" alt=""> -->
              </div>
            </div>
            <div class="limit_prd_tips"></div>
            <div class="limit_prd_leaf"></div>
          </div>
        </template>
      </div>
    </div>
  </div>
</template>

<script>
import Tool from '@/utils/tool.js'
import Domain from '@/utils/domain.js'

export default {
  // components: { Swipe, PrdItem },
  data () {
    return {
      active: 1,
      first_show: false,
      last_show: false,
      isVip: false,
      prd_list: [],
      active_prd: '',
      parent_info: [],
      mit_tips: [
        '每家每户一年买两床冬被，两床夏被，三口之家，一年就省3468元'
      ]
    }
  },
  created () {
    this.getPrdList()
    let token = sessionStorage.getItem('token')
    if (token) {
      this.getProfile()
    } else {
      this.isVip = false
      this.loading = true
    }
  },
  methods: {
    share () {
      var url = encodeURIComponent('pages/activity/join_vip/join_vip?invite=' + this.user_info.invite_id)
      var title = encodeURIComponent('倾情推荐！开启超级会员之旅，超值特权嗨不停。')
      var desc = encodeURIComponent('Hi，我是' + this.user_info.user_nickname + '分享一个正品购物平台给你')
      var imgurl = encodeURIComponent(Domain('/wechat/images/v4/share_vip.png'))
      let isClient = Tool.isClient()
      if (isClient) {
        window.location = 'yggshare://title=' + title + '&desc=' + desc + '&imgurl=' + imgurl + '&url=' + url
      } else {
        this.$toast('h5分享微信')
      }
    },
    getPrdList () {
      return new Promise((resolve, reject) => {
        this.$Axios({ url: 'product', params: { is_gift_bag: 1, pagesize: 100 }, method: 'get' }).then((resp) => { // 请求成功
          if (resp.return_code === '0000') {
            this.prd_list = resp.data.list
          }
          resolve(resp)
        }).catch((error) => { // 请求失败
          this.$_requestInterceptor('error', error)
          reject(error)
        })
      })
    },
    getProfile () {
      return new Promise((resolve, reject) => {
        this.$Axios({ url: 'profile', method: 'get' }).then((resp) => { // 请求成功
          this.loading = false
          if (resp.return_code === '0000') {
            if (resp.data.user_info.lev_code === 'COMMON_USER') {
              this.isVip = false
            } else {
              this.isVip = true
            }
          }
          resolve(resp)
        }).catch((error) => { // 请求失败
          this.$_requestInterceptor('error', error)
          reject(error)
        })
      })
    },
    showTips (e, prdInfo) {
      this.first_show = true
      this.active_prd = prdInfo
      this.parent_info = e.data
    },
    againOpenTips () {
      this.first_show = false
      this.last_show = true
    },
    closeTips () {
      this.first_show = false
      this.last_show = false
    },
    continueBuy (item) {
      let isMini = sessionStorage.getItem('isMini')
      let params = '?pid=' + item.id + '&item_id=' + item.default_item_id
      if (isMini) {
        window.wx.miniProgram.navigateTo({ url: '/pages/shopDetails/shopDetails' + params })
      } else {
        this.$router.push('/main/shopDetails' + params)
      }
    },
    goToEquity (i) {
      this.$router.push('/active/equity?id=' + i)
    },
    getImgBuyUrl () {
      return require('@/assets/image/member/vip_prd_buy_btn.png')
    },
    getImgInviteUrl () {
      return require('@/assets/image/member/vip_prd_invite_btn.png')
    }
  }
}
</script>
